#ifndef __G_INPUT_MODULE_RAW_H__
#define __G_INPUT_MODULE_RAW_H__

#define WIN32_LEAN_AND_MEAN
#include <Windows.h>

#include <vector>

#include "GModule.h"
#include "GSpinMutex.h"
#include "GMessageManager.h"
#include "GMessageHandler.h"
#include "GInputModule.h"

#define G_MAX_RAW_INPUT_COUNT	128

namespace GEngine
{
	class GWindow;
	class GSystemMessage;
	class GMessageHandler;
	class GInputManager;
}

namespace GRawInput
{
	class GRawInputModule;

	class GRawInputMessageHandler : public GEngine::GMessageHandler
	{
	private:
		GRawInputModule*	Module;

	public:
							GRawInputMessageHandler();
							~GRawInputMessageHandler();

		void				SetTargetModule( GRawInputModule* NewModule);
		GRawInputModule*	GetTargetModule() const;

		GSSize				HandleMessage(const GEngine::GSystemMessage* Message) OVERRIDE PLATFORM;

	};

	class GRawInputDeviceMouse;
	class GRawInputDeviceKeyboard;

	class GRawInputModule : public GEngine::GInputModule
	{
	G_MODULE(GRawInputModule);

	typedef std::vector<RAWINPUT> InputArray;
	
	private:
		GRawInputMessageHandler*	MessageHandler;

		GThread::GSpinMutex			BufferLock;
		InputArray					InputBuffer;

		GRawInputDeviceMouse*		RawMouse;
		GRawInputDeviceKeyboard*	RawKeyboard;

									GRawInputModule();
									~GRawInputModule();

		bool						RegisterDevices();
		bool						EnumerateDevices();

	public:
		bool						HandleInput(HRAWINPUT InputHandle);

		virtual void				Reset() OVERRIDE;
		virtual bool				Update(float ElapsedTime) OVERRIDE;

		virtual bool				Initialize() OVERRIDE;
		virtual void				Uninitialize() OVERRIDE;

	};
}


#endif